// ====================== // globals // ====================== // ----- serial port import processing.serial.*; //import the serial library Serial myPort; //the Serial port object final int Baud_rate = 9600; //communication speed String Input_string; //for incoming data boolean Connected = false; //flag // ----- display graphics PGraphics Canvas; //name of drawing area to be created PFont myFont; //name of font to be created // ----- ultrasonic beam int Azimuth = 0; //radians (180 degrees equals PI radians) int [][] Ping = new int [257][2]; //257 rows of 2 columns int Direction = 0; //scan direction: true=CW, false=CCW // ====================== // setup // ====================== void setup() { // ----- image window //size(900, 600, P3D); //P3D parameter allows rotation around Z-axis //size(1200, 800, P3D); //P3D parameter allows rotation around Z-axis size(1050, 700, P3D); // ----- create a drawing area for fading the beam Canvas = createGraphics(width, height); // ------ create the screen font myFont = createFont("Arial Black", 20); // ----- initialize the serial port printArray(Serial.list()); //lists your COM ports on screen myPort = new Serial(this, Serial.list()[2], Baud_rate); myPort.bufferUntil('\n'); } // ====================== // draw // ====================== void draw() { // ----- define colors, scale, & text background(0); //black background textFont(myFont, 20); //specify font to be used // ----- draw beam on its own canvas Canvas.beginDraw(); Canvas.translate(width/2, height*0.8); //beam origin Canvas.stroke(0, 255, 0); //green beam Canvas.strokeWeight(7); //set beam-width Canvas.scale(0.8); //think 100% but scale 80% Canvas.rotate(-Azimuth*PI/256); //rotate "sheet of paper" but Canvas.line(0, 0, width/2, 0); //think horizontal lines Canvas.endDraw(); // ----- draw the graticule draw_graticule(); // ----- plot CCW data if (Direction == 0) { for (int i=0; i100) Ping[index][0] = 1000; //hide by printing off-screen ellipse(width/2*Ping[index][0]/100, 0, 5, 5); //plot data1 stroke(0, 0, 255); //set data2 color to blue if (Ping[index][1]>100) Ping[index][1] = 1000; //hide by printing off-screen ellipse(width/2*Ping[index][1]/100, 0, 5, 5); //plot data2 // ----- restore defaults strokeWeight(1); stroke(0); popMatrix(); //restore screen parameters } // ======================= // fadeGraphics // ======================= /* This fadeGraphics() routine was found at https://forum.processing.org/two/discussion/13189/a-better-way-to-fade */ void fadeGraphics(PGraphics c, int fadeAmount) { c.beginDraw(); c.loadPixels(); // ----- iterate over pixels for (int i =0; i> 24) & 0xFF ; // ----- reduce alpha value alpha = max(0, alpha-fadeAmount); // ----- assign color with new alpha-value c.pixels[i] = alpha<<24 | (c.pixels[i]) & 0xFFFFFF ; } Canvas.updatePixels(); Canvas.endDraw(); }